package cn.jupiter.servlet;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;

import cn.jupiter.db.DbUtils;
import cn.jupiter.db.Map2DataBase;
import cn.jupiter.json.Json2Map;
import cn.jupiter.json.RestResource;

public class InsertTypeWorker extends TypeWorker  {
	public InsertTypeWorker(HttpServletRequest request){
		super(request);
	}
	public int execute() {
		String url =super.getRequest().getRequestURL().toString();
		//��������url����
		String json=super.getRequest().getParameter("json");
		Json2Map jm=new Json2Map();
		jm.setJson(json);
		jm.parse();
		RestResource r=RestUrlParser.parserUrl(url);
		r.setRow(jm.getRows());
		Map2DataBase m=new Map2DataBase();
		Connection conn;
		try {
			conn = DbUtils.getConn();
			m.insertJson(conn, r);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return m.getCode();

	}

}
